package com.yadang.infra.controller;

import com.yadang.infra.bean.CmmDictDetail;
import com.yadang.infra.service.CmmService;
import com.yadang.infra.tools.SnowFlakeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.lang.invoke.MethodHandles;

@Api(tags = "字典详情表接口")
@RestController
@RequestMapping("/infra/cmmDictDetail")
public class CmmDictDetailController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
    @Autowired
    private CmmService cmmService;

    @ApiOperation("查询所有字典映射的key和value值")
    @PostMapping("/getCmmDictById")
    public CmmDictDetail getCmmDictById(String id) {
        id = SnowFlakeUtil.getId();
        LOGGER.info("id是：[{}]", id);
        CmmDictDetail cmmDictDetail = cmmService.getCmmDictById(id);
        System.out.println(cmmDictDetail);
        return cmmDictDetail;
    }

    @ApiOperation("生成全局唯一ID接口,传递一个前缀")
    @GetMapping("/getId")
    public String getId(@ApiParam("前缀") @RequestParam(required = false) String prefix) {
        if (StringUtils.hasText(prefix)) {
            return prefix + SnowFlakeUtil.getId();
        }
        return SnowFlakeUtil.getId();
    }

}
